package com.zr.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.zr.dao.FuncDao;
import com.zr.dao.RoleDao;
import com.zr.service.FuncService;

import net.sf.json.JSONArray;
@Repository(value="funcservice")
public class FuncServiceImpl implements FuncService{
	@Resource
	private FuncDao funcdao;
	@Resource
	private RoleDao roledao;
	@Override
	public JSONArray getCurrentFuncsByPartentId(int parentid, int rid) {
		// TODO Auto-generated method stub
		String ids = roledao.selectRoleByRid(rid).getFuncs();
		JSONArray userFuns = funcdao.getFuncByParentIdAndFids(parentid, ids);
		for (int i = 0; i < userFuns.size(); i++) {
			String state = userFuns.getJSONObject(i).getString("state");
			if("open".equals(state)){
				continue;
			}else{
				
				int currentId = userFuns.getJSONObject(i).getInt("id");
				JSONArray children = this.getCurrentFuncsByPartentId(currentId, rid);
				userFuns.getJSONObject(i).put("children", children);
			}
		}
		return userFuns;
	}

}
